/**
 * @file EndState.cpp
 *
 * Implementación de EndState.h
 *
 * @see EndState.h
 */

#include <PlayState.h>
#include <EndState.h>

template<> EndState* Ogre::Singleton<EndState>::ms_Singleton = 0;

EndState::EndState() {
  _endType = 0; }

EndState::~EndState() throw() {}

void EndState::enter()
{
  _exitGame = false;
  _overlayManager = Ogre::OverlayManager::getSingletonPtr();
  SoundFXManager* soundFXManager = SoundFXManager::getSingletonPtr();
  _win = soundFXManager->load("you_win.ogg");
  _lose = soundFXManager->load("game_over.ogg");

  if (_endType == 0)
  {
    std::cout << "MUEROOOOOOOOOOOO" << std::endl;
    _overlayManager->getOverlayElement("lose")->show();
    _lose->play();
    
  }

  else
  {
    _overlayManager->getOverlayElement("win")->show();
    _win->play();
  }
}

void EndState::exit() {}

void EndState::pause() {}

void EndState::resume() {}

bool EndState::frameStarted(const Ogre::FrameEvent& evt) {
  return true; }

bool EndState::frameEnded(const Ogre::FrameEvent& evt) {
  return not _exitGame; }

void EndState::keyPressed(const OIS::KeyEvent& e)
{
  if (e.key == OIS::KC_ESCAPE)
    _exitGame = true;
}

void EndState::keyReleased(const OIS::KeyEvent& e) {}

void EndState::mouseMoved(const OIS::MouseEvent& e) {}

void EndState::mousePressed(const OIS::MouseEvent& e, OIS::MouseButtonID id) {}

void EndState::mouseReleased(const OIS::MouseEvent& e, OIS::MouseButtonID id) {}

EndState* EndState::getSingletonPtr() { return ms_Singleton; }

EndState& EndState::getSingleton()
{
  assert(ms_Singleton);
  return *ms_Singleton;
}

void EndState::set(const int i) {
  _endType = i; }
